<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-08 20:08
 *
 * Version: 2.0
 */

namespace App\Modules\DataCenter\Controllers;


use App\Lib\Facades\FLAuth;
use App\Lib\Utilities;
use App\Modules\DataCenter\Services\BarberStatisticsService;
use App\Modules\Employee\Services\EmployeeService;
use App\Modules\MemberCard\Services\MemberCardService;
use App\Modules\Order\Services\OrderService;
use Flower\Core\Http\BaseController;
use Flower\Core\Http\Request;
use Illuminate\Support\Facades\Redis;

class BarberStatisticsController extends BaseController
{
    private $employeeService;
    private $memberCardService;
    private $orderService;
    private $barberStatisticsService;

    public function __construct(EmployeeService $employeeService,
                                MemberCardService $memberCardService,
                                BarberStatisticsService $barberStatisticsService,
                                OrderService $orderService)
    {
        $this->employeeService = $employeeService;
        $this->memberCardService = $memberCardService;
        $this->orderService = $orderService;
        $this->barberStatisticsService = $barberStatisticsService;
    }

    public function getRules()
    {
        return [
            'getBarberDataCenterHeader' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getBarberDataYesterdayOverview' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getBarberVisitorRecord' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getBarberCenterOrderList' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getOrderData' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getPieChartOrderData' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getMemberCardDataCenter' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getOrderPointData' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getOrderServiceData' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getOrderServiceList' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getCenterUserSalaryList' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getCenterUserMonthSalaryList' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
            'getBarberCenterAll' => [
                'store_id' => [
                    'title' => '店铺id',
                    'rule' => 'required',
                    'message' => []
                ]
            ],
        ];
    }

    /**
     * 我的工资详情
     * @param Request $request
     * @return mixed
     */
    public function getMySalaryInfo(Request $request)
    {
        $res = $this->employeeService->getMySalaryInfo($request->all());
        return $this->display($res, '工资列表');
    }


    /**
     * 查询某理发师某店铺某天的新增的会员卡数据
     * @param Request $request
     * @return mixed
     */
    public function getBarberDayMemberCard(Request $request)
    {
        $res = $this->memberCardService->getDayMemberCard($request->all());
        return $this->display($res);
    }

    /**
     * 今日新增会员卡 数据
     * @param $request
     * @return mixed
     */
    public function getBarberTodayMemberCard(Request $request)
    {
        $res = $this->memberCardService->statisticsMemberCard($request->all());
        return $this->display($res);
    }

    /**
     * 今日服务 今日工资 今日积分
     * @param Request $request
     * @return mixed
     */
    public function getBarberTodayData(Request $request)
    {
        $res = $this->orderService->orderBarberToday($request->all());
        return $this->display($res);
    }

    /**
     * 近七天的提成
     * @param Request $request
     * @return mixed
     */
    public function weekRoyalty(Request $request)
    {
        $res = $this->orderService->weekRoyalty($request->all());
        return $this->display($res);
    }

    /**
     * 获取某理发某天的工资详情
     * @param Request $request
     * @return mixed
     */
    public function getBarberOneDaySalary(Request $request)
    {
        $res = $this->orderService->getSingleSalary($request->all());
        return $this->display($res);
    }

    /**
     * 定时任务 理发师排名写入数据库
     * @return mixed
     */
//    public function userRank()
//    {
//        $res = $this->employeeService->userRank();
//        if (!$res) return $this->error("理发师排名数据插入表失败！");
//        return $this->success("理发师排名数据插入表成功！");
//    }

    /**
     * 获取理发师排名
     * @param Request $request
     * @return mixed
     */
//    public function getUserRank(Request $request)
//    {
//        $res = $this->employeeService->getUserRank($request->all());
//        if (!$res) return $this->error("理发师排名查询失败！");
//        return $this->display($res, "理发师排名查询成功！");
//    }

	/**
	 * 理发师人员工资定时任务
	 * @return mixed
	 * @throws \App\Exceptions\NotFoundException
	 */
    public function barberSalaryAdd()
    {
    	$res = $this->employeeService->barberSalaryAdd();
        if (!$res) return $this->error("定时任务理发师工资插入失败！");
        return $this->success("定时任务理发师工资插入成功！");
    }

    /**
     * ========================================================================
     */

    /*
     * 获取理发师数据中心头部信息
     */
    public function getBarberDataCenterHeader(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $data = $this->barberStatisticsService->getBarberDataCenterHeader($user_id, $store_id);

        return $this->display($data, "查询成功");
    }
    /*
     * 获取理发师数据中心经营分析
     */
    public function getBarberDataBusinessAnalysis(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $date_type = $request->input('date_type');
        $data = $this->barberStatisticsService->getBarberDataBusinessAnalysis($user_id, $store_id, $date_type);

        return $this->display($data, "查询成功");
    }

    /*
     * 获取理发师数据中心经营分析详情
     */
    public function getBarberDataBusinessAnalysisDetails(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $type = $request->input('type');
        $date_type = $request->input('date_type',0);
        $pageSize = $request->input('pageSize',10);
        $data = $this->barberStatisticsService->getBarberDataBusinessAnalysisDetails($user_id, $store_id, $type,$date_type,$pageSize);

        return $this->display($data, "查询成功");
    }

    /*
     * 获取理发师数据中心昨日经营数据
     */
    public function getBarberDataYesterdayOverview(Request $request)
    {

        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $data = $this->barberStatisticsService->getBarberDataOverview($user_id, $store_id);

        return $this->display($data, "查询成功");
    }

    /*
     * 获取理发师数据中心访客记录
     */
    public function getBarberVisitorRecord(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $dateType = $request->input('date_type', 0);
        $data = $this->barberStatisticsService->getBarberVisitorRecord($user_id, $store_id, $dateType);

        return $this->display($data, "查询成功");
    }

    /**
     * 理发师数据中心 访客数据列表
     * @param Request $request
     * @return mixed
     */
    public function getbarberVisitorList(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $dateType = $request->input('date_type', 0);
        $pageSize = $request->input('pageSize', 10);
        $list = $this->barberStatisticsService->getVisitorList($user_id,$store_id, $dateType,$pageSize);
        return $this->display($list);
    }

    /**
     * 获取理发师订单列表
     * @param Request $request
     */
    public function getBarberCenterOrderList(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $page_size = $request->input('page_size', 10);
        $date_type = $request->input('date_type', 0);
        $list = $this->barberStatisticsService->getOrderList($user_id, $store_id, $page_size, $date_type);
        return $this->display(Utilities::dealPage($list));
    }

    /**
     * 获取订单统计
     * @param Request $request
     * @return mixed
     */
    public function getOrderData(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $page_size = $request->input('page_size', 10);
        $date_type = $request->input('date_type', 0);
        $list = $this->barberStatisticsService->getOrderData($user_id, $store_id, $page_size, $date_type);
        return $this->display($list);
    }

    /**
     * 理发师数据中心 订单饼图数据
     * @param Request $request
     * @return mixed
     */
    public function getPieChartOrderData(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $date_type = $request->input('date_type', 0);
        $list = $this->barberStatisticsService->getPieChartOrderData($user_id, $store_id, $date_type);
        return $this->display($list);
    }

    /**
     * 理发师数据中心 会员卡数据
     * @param Request $request
     * @return mixed
     * @throws \Flower\Core\Repository\Exceptions\RepositoryException
     */
    public function getMemberCardDataCenter(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $date_type = $request->input('date_type', 0);
        $list = $this->barberStatisticsService->getMemberCardDataCenter($user_id, $store_id, $date_type);
        return $this->display($list);
    }

    public function getCardFlowDataCenter(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $date_type = $request->input('date_type', 0);
        $pageSize = $request->input('pageSize', 10);
        $list = $this->barberStatisticsService->getFlowList($store_id, $pageSize, $date_type,$user_id);
        return $this->display(Utilities::dealPage($list));
    }

    /**
     * 获取指定用户
     * @param Request $request
     * @return mixed
     * @throws \App\Exceptions\AllValidatorException
     */
    public function getOrderPointData(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $page_size = $request->input('pageSize', 10);
        $date_type = $request->input('date_type', 0);
        $list = $this->barberStatisticsService->getOrderPointData($user_id, $store_id, $date_type, $page_size);
        return $this->display($list);
    }

    /**
     * 获取指定用户三条
     * @param Request $request
     * @return mixed
     * @throws \App\Exceptions\AllValidatorException
     */
    public function getOrderPoint(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $date_type = $request->input('date_type', 0);
        $list = $this->barberStatisticsService->getOrderPoint($user_id, $store_id, $date_type);
        return $this->display($list);
    }

    /**
     * 服务排名数据
     * @param Request $request
     * @return mixed
     */
    public function getOrderServiceData(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $date_type = $request->input('date_type', 0);
        $is_amount = $request->input('is_amount',1);
        $is_limit = $request->input('is_limit');
        $list = $this->barberStatisticsService->getOrderServiceData($user_id, $store_id, $date_type, $is_amount, $is_limit);
        return $this->display($list);
    }


    /**
     * 订单服务排名列表
     * @param Request $request
     * @return mixed
     * @throws \Flower\Core\Repository\Exceptions\RepositoryException
     */
    public function getOrderServiceList(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $service_id = $request->input('service_id');
        $page_size = $request->input('page_size', 10);
        $date_type = $request->input('date_type', 0);
        $list = $this->barberStatisticsService->getOrderServiceList($user_id, $store_id, $service_id, $page_size, $date_type);
        $list = Utilities::dealPage($list);
        return $this->display($list);

    }


    /**
     * 工资列表
     * @param Request $request
     * @return mixed
     */
    public function getCenterUserSalaryList(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $list = $this->barberStatisticsService->getCenterUserSalaryList($user_id, $store_id);
        return $this->display($list);
    }

    public function getCenterUserMonthSalaryList(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $month = $request->input('month', date('Y-m', time()));
        $list = $this->barberStatisticsService->getCenterUserMonthSalaryList($user_id, $store_id, $month);
        return $this->display($list);
    }

    public function getBarberCenterAll(Request $request)
    {
        $user_id = FLAuth::id();
        $store_id = $request->input('store_id');
        $dateType = $request->input('date_type', 0);
        $page_size = $request->input('page_size', 10);
        $is_amount = $request->input('is_amount');
        $is_limit = $request->input('is_limit');

        $data = [
            'head'=>$this->barberStatisticsService->getBarberDataCenterHeader($user_id,$store_id),
            'analysis'=>['items'=>$this->barberStatisticsService->getBarberDataBusinessAnalysis($user_id,$store_id,$dateType)],
            'buss'=>['items'=>$this->barberStatisticsService->getBarberDataOverview($user_id,$store_id)],
            'visitor'=>$this->barberStatisticsService->getBarberVisitorRecord($user_id,$store_id,$dateType),
            'order_rate'=>$this->barberStatisticsService->getPieChartOrderData($user_id,$store_id,$dateType),
            'member_card'=>$this->barberStatisticsService->getMemberCardDataCenter($user_id,$store_id,$dateType),
            'service_rank'=>['items'=>$this->barberStatisticsService->getOrderServiceData($user_id, $store_id, $dateType, 1, $is_limit)],
            'wage'=>$this->barberStatisticsService->getCenterUserSalaryList($user_id,$store_id)
        ];
        return $this->display($data);
    }

//            'order'=>$this->barberStatisticsService->getOrderData($user_id,$store_id,$page_size,$dateType),
//            'order_point' => ['items'=>$this->barberStatisticsService->getOrderPoint($user_id,$store_id,$dateType)],
}